package com.sikhyeon.datastructure.model;

public class Stack {
    public static final int MAX_SIZE = 10;
    private int[] elements;
    private int top;

    public Stack() {
        elements = new int[MAX_SIZE];
        top = -1;
    }

    public void push(int value) {
        if (top < MAX_SIZE - 1) {
            elements[++top] = value;
        } else {
            System.out.println("Stack overflow");
        }
    }

    public int pop() {
        if (top >= 0) {
            return elements[top--];
        } else {
            System.out.println("Stack underflow");
            return -1;
        }
    }

    public int peek() {
        if (top >= 0) {
            return elements[top];
        } else {
            System.out.println("Stack is empty");
            return -1;
        }
    }

    public boolean isEmpty() {
        return top == -1;
    }

    public boolean isFull() {
        return top == MAX_SIZE - 1;
    }

    public int[] getElements() {
        int[] currentElements = new int[top + 1];
        System.arraycopy(elements, 0, currentElements, 0, top + 1);
        return currentElements;
    }

    public int getSize() {
        return top + 1;
    }
}
